import 'package:flutter/material.dart';
import 'package:aio/aio.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/manager/audit_manager.dart';
import 'package:app/src/presenter/review_presenter.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/ui/route/works/public/acom/ui_payfree_adapter1.dart';
import 'package:app/src/ui/route/works/public/acom/ui_payfree_adapter2.dart';
import 'package:app/src/ui/route/works/public/acom/ui_payfree_adapter3.dart';
import 'package:app/src/ui/route/works/public/acom/ui_payfree_adapter4.dart';
import 'package:app/src/ui/route/works/public/image/ui_image.dart';
import 'package:app/src/ui/route/works/public/image/ui_image_upload.dart';
import 'package:app/src/ui/route/works/public/items/ui_attachment.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_contractInfo.dart';
import 'package:app/src/ui/route/works/public/items/ui_customersInfo.dart';
import 'package:app/src/ui/route/works/public/items/ui_new_customer.dart';
import 'package:app/src/ui/route/works/public/items/ui_node_list.dart';
import 'package:app/src/ui/route/works/public/items/ui_note.dart';
import 'package:app/src/ui/route/works/public/acom/ui_order_item_info.dart';
import 'package:app/src/ui/route/works/public/items/ui_payfree.dart';
import 'package:app/src/ui/route/works/public/items/ui_payment.dart';
import 'package:app/src/ui/route/works/public/items/ui_paynotice.dart';
import 'package:app/src/ui/route/works/public/acom/ui_paynotice_details_info.dart';
import 'package:app/src/ui/route/works/public/acom/ui_process_info.dart';
import 'package:app/src/ui/route/works/public/items/ui_process_list.dart';
import 'package:app/src/ui/route/works/public/acom/ui_product.dart';
import 'package:app/src/ui/route/works/public/items/ui_product_info.dart';
import 'package:app/src/ui/route/works/public/acom/ui_receipt_details_info.dart';
import 'package:app/src/ui/route/works/public/items/ui_specialclauses.dart';
import 'package:app/src/ui/route/works/public/review_details_ui.dart';
import 'package:app/src/ui/route/works/public/review_submitted.dart';

///免款审核详情
class PayfreeDetailsRoute extends StatefulWidget {
  PayfreeDetailsRoute();

  @override
  _State createState() => _State();
}

class _State extends State<PayfreeDetailsRoute> {
  _Presenter presenter = _Presenter();

  @override
  void initState() {
    super.initState();
    presenter.getContractapplygetinfoWithDelay(context); //获取审核详情数据
  }

  @override
  Widget build(BuildContext context) {
    return ReviewDetailsUi.build(context, presenter, _body);
  }

  Widget _body(BuildContext context) {
    if (presenter?.mDatas == null) {
      return AppUi.getEmptyView();
    }
    List<Widget> children = [];
    children.add(UiPayFreeInfo.build(context, presenter?.mDatas?.PayFreeInfo,
        presenter?.mOldDatas?.PayFreeInfo,
        title: AppStrings.of(context).PayFreeInfo)); //免款信息
    children.add(UiNote.build(context, presenter?.mDatas?.PayFreeInfo?.Intro,
        presenter?.mOldDatas?.PayFreeInfo?.Intro,
        title: AppStrings.of(context).Intro2)); //免款说明
    children.add(UiImage.build(context, presenter?.mDatas?.PicList)); //图片证据
    children.add(UiImageUpLoad.build(
        context, presenter?.mDatas?.PayFreeInfo?.ReviewTypeName)); //上传证据
    var FreeType = presenter?.mDatas?.PayFreeInfo?.FreeType?.trim();
    if ("免单" == FreeType) {
      children.add(UiPayFreeAdapter1.build(
          context, presenter?.mDatas?.PayFreeDetails)); //免款信息：免单
    } else if ("下账" == FreeType) {
      children.add(UiPayFreeAdapter2.build(
          context, presenter?.mDatas?.PayFreeDetails)); //免款信息：下账
    } else if ("免款" == FreeType) {
      var IsCheck = presenter?.mDatas?.PayFreeInfo?.IsCheck;
      if (BoolUtils.isBoolWithStr(IsCheck)) {
        //已对账
        children.add(UiPayFreeAdapter4.build(
            context, presenter?.mDatas?.PayFreeDetails)); //免款信息：免款(已对账)
      } else {
        //未对账
        children.add(UiPayFreeAdapter3.build(
            context, presenter?.mDatas?.PayFreeDetails)); //免款信息：免款(未对账)
      }
    }
    children.add(UiAttachment.build(context, presenter?.mDatas?.FileList)); //附件
    children.add(UiNoteList.build(context, presenter?.mDatas?.NodeList)); //审核日志
    return Column(
      children: [
        Expanded(child: UiBase.listView(context, children)),
        Visibility(
            child: ReviewSubmittedStateful(
              presenter?.mDatas,
              hasEnd: false,
            ),
            visible: presenter?.mDatas != null)
      ],
    );
  }
}

class _Presenter extends ReviewPresenter {}
